package com.ruoyi.StarStudio.Mapper;

import com.ruoyi.StarStudio.Domain.Warning;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface WarningMapper {

    @Select("select * from " +
            "(select wr.*, z.zone_name " +
            "from warning wr, zone z " +
            "where wr.warning_zoneid = z.zone_id) w ")
    List<Warning> getAll();

    @Select("select * from " +
            "(select wr.*, z.zone_name " +
            "from warning wr, zone z " +
            "where wr.warning_zoneid = z.zone_id) w " +
            "where warning_zoneid = #{zone_id} order by warning_id desc limit 1")
    Warning getByZoneId(Integer zone_id);

    @Update("update warning set " +
            "meteorology_temperatureLowerLimit=#{meteorology_temperatureLowerLimit},meteorology_temperatureUpperLimit=#{meteorology_temperatureUpperLimit}," +
            "meteorology_humidityLowerLimit=#{meteorology_humidityLowerLimit},meteorology_humidityUpperLimit=#{meteorology_humidityUpperLimit}," +
            "meteorology_co2LowerLimit=#{meteorology_co2LowerLimit},meteorology_co2UpperLimit=#{meteorology_co2UpperLimit}," +
            "meteorology_illuminanceLowerLimit=#{meteorology_illuminanceLowerLimit},meteorology_illuminanceUpperLimit=#{meteorology_illuminanceUpperLimit}," +
            "meteorology_rainfallLowerLimit=#{meteorology_rainfallLowerLimit},meteorology_rainfallUpperLimit=#{meteorology_rainfallUpperLimit}," +
            "meteorology_windSpeedLowerLimit=#{meteorology_windSpeedLowerLimit},meteorology_windSpeedUpperLimit=#{meteorology_windSpeedUpperLimit}," +
            "soil_temperatureLowerLimit=#{soil_temperatureLowerLimit},soil_temperatureUpperLimit=#{soil_temperatureUpperLimit}," +
            "soil_moistureLowerLimit=#{soil_moistureLowerLimit},soil_moistureUpperLimit=#{soil_moistureUpperLimit}," +
            "soil_phLowerLimit=#{soil_phLowerLimit},soil_phUpperLimit=#{soil_phUpperLimit}," +
            "warning_updatetime=#{warning_updatetime},warning_zoneid=#{warning_zoneid} " +
            "where warning_id = #{warning_id}")
    void update(Warning warning);

}
